/*
 * @Author: 9ilk 3535851673@qq.com
 * @Date: 2024-11-29 21:36:40
 * @LastEditors: 9ilk 3535851673@qq.com
 * @LastEditTime: 2025-01-03 20:37:58
 * @FilePath: /zhuang/RingBuffer/Main.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <ctime>
#include <functional>
#include<pthread.h>
#include<unistd.h>
#include"RingBuffer.hpp"
#include"Sem.hpp"
using namespace RingBufferModule;



void *Consumer(void *args)
{   
     RingBuffer<int> *bq = static_cast<RingBuffer<int> *>(args);
    while (true)
    {
       
        int data;
        bq->Pop(&data);
        cout << "消费了一个数据："<< data <<endl;
    }
}

void *Producter(void *args)
{    RingBuffer<int> *bq = static_cast<RingBuffer<int> *>(args);
    // 1.从外部获取数据
    int data = 0;
    while (true)
    {
        
        bq->Equeue(data);
        cout << "生产了一个数据：" << data << endl;
        data++;
    }
}

int main()
{
    RingBuffer<int> * ring_buffer = new RingBuffer<int>(5);  
    // 单生产 单消费
    pthread_t c1, p1, c2, p2, p3;
    pthread_create(&c1, nullptr, Consumer, ring_buffer);
    pthread_create(&p1, nullptr, Producter, ring_buffer);
    pthread_join(c1, nullptr);
    pthread_join(p1, nullptr);
    return 0;
}